package com.ciei.dpagm.service.conditionRule.standardSpecification;

import com.alibaba.fastjson.JSONObject;
import com.ciei.dpagm.common.enums.StandardSpecificationEnum;
import com.ciei.dpagm.service.conditionRule.ConditionHandleService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author pp
 * @date 2023/03/19
 */
@Service
public class StandardSpecificationFactoryService {
    public static Integer oneStandardSpecificationIndex = 0;
    public static Integer twoStandardSpecificationIndex = 1;
    public static Integer threeStandardSpecificationIndex = 2;
    public static Integer parameterModelIndex = 1;
    public static Integer parameterModuleIndex = 2;
    public static Integer parameterTypeIndex = 3;
    public static Integer parameterValueIndex = 4;
    public static String title = "标准规范";

    /**
     * 解析
     * @param factModeList 事实方式列表
     * @param comparator 比较符
     * @param standardSpecificationList 标准规范列表
     * @param oldStandardSpecificationList 旧标准规范列表
     * @return
     */
    public JSONObject analysis(List<String> factModeList, Integer comparator, List<String> standardSpecificationList,List<String> oldStandardSpecificationList){
        String standardSpecification = standardSpecificationList.get(0);
        AbstractStandardSpecificationService abstractStandardSpecificationService = getSonService(standardSpecification);
        if(abstractStandardSpecificationService == null){
            return ConditionHandleService.notMatchSonServiceMessage(title);
        }

        return abstractStandardSpecificationService.analysis(factModeList,comparator,standardSpecificationList,oldStandardSpecificationList);
    }
    /**
     * 转换下拉框列表
     * @param standardSpecificationList 标准规范列表
     * @param sonStandardSpecificationOptionDataList 子标准规范下拉框数据列表
     * @return
     */
    public void conversionOptionList(List<String> standardSpecificationList,List<JSONObject> sonStandardSpecificationOptionDataList){
        String standardSpecification = standardSpecificationList.get(0);
        AbstractStandardSpecificationService abstractStandardSpecificationService = getSonService(standardSpecification);
        if(abstractStandardSpecificationService == null){
            return;
        }
        abstractStandardSpecificationService.conversionOptionList(standardSpecificationList,sonStandardSpecificationOptionDataList);
    }

    /**
     * 获取子类
     * @param standardSpecification
     * @return
     */
    private AbstractStandardSpecificationService getSonService(String standardSpecification){
        StandardSpecificationEnum standardSpecificationEnum = StandardSpecificationEnum.getEnumByValue(Integer.valueOf(standardSpecification));
        if(standardSpecificationEnum == null){
            return null;
        }
        AbstractStandardSpecificationService abstractStandardSpecificationService = null;
        switch (standardSpecificationEnum) {
            case SELECT_PARAMETER:
                abstractStandardSpecificationService = new SelectParameterStandardSpecificationService();
                break;
            default:
                break;
        }
        return abstractStandardSpecificationService;
    }
}
